function getdec(tables)
{
      $.getJSON(
            "adminajax.php",
            {
                act:"getdec",
                tb:tables
            },
            function(json){
		    for(key in json){
                        //alert(json[key]);
                        $("#"+key).html(json[key]);
                    }
            });
}


function sendrecom(ids)
{
    $.post("adminajax.php?act=recom", {
        id: ids,
        recom: $("#recom"+ids).val()
    } );
    $("#msg").html(ids+"修改成功");
}


function ajaxsend(actset,inputid,showmsg)
{
    $.ajax({
        beforeSend:function(){
            $("#msg").html("正在建立链接..");
        },
        dataType:"json",
        type: "post",
        url:"adminajax.php?act="+actset,
        data: $("#"+inputid+" :input").serialize(),
        success: function(json){
           
            if(json.msg)
            {
                if(showmsg)
                {
                    alert(json.msg);
                }
                $("input[type=reset]").click();
                $("#msg").html(json);
                if($("#loadbody").text()!="")
                {
                    $("#loadbody").load(window.location.href+"?"+Math.random()+" #loadbody",function(){});
                }
            }
            else
            {
                alert(json.error);
                $("#msg").html(json.error);
                   

            }
          
        },
        error:function(){
            $("#msg").html("链接出错");
        }
    });
}


function upprice(ids)
{
    //  $("#catid");
    if(!$("#catid").val())
    {
        $.getJSON(
            "adminajax.php",
            {
                act:"json",
                tb:"cardcat",
                rval:"id,catname", //不要有sql关键字
                where:" where pcatid!=0"
            },

            function(json){
                $("#catid").empty();
                $("#catid").append("<option value=\"\">请选择</option>");
                $.each(json,function(i,n){
                    $("#catid").append("<option value=\""+json[i].id+"\">"+json[i].catname+"</option>");
                });
            });
    }
    else
    {
        if(ids!=1)
        {
            $.getJSON(
                "adminajax.php",
                {
                    act:"json",
                    tb:"card",
                    rval:"id,title", //不要有sql关键字
                    where:" where menu="+$("#catid").val()
                },
                function(json){
                
               
                    $("#cardid").empty();
                    $("#cardid").append("<option value=\"\">请选择</option>");
                    $.each(json,function(i,n){
                        $("#cardid").append("<option value=\""+json[i].id+"\">"+json[i].title+"</option>");
                    });

                });

        }
        else
        {
              $.getJSON(
                        "adminajax.php",
                        {
                            act:"json",
                            tb:"price",
                            rval:"id,price_text", //不要有sql关键字
                            where:" where cardid="+$("#cardid").val()
                        },
                        function(json){


                            $("#priceid").empty();
                            $("#priceid").append("<option value=\"0\">默认</option>");
                            $.each(json,function(i,n){
                                $("#priceid").append("<option value=\""+json[i].id+"\">"+json[i].price_text+"</option>");
                            });

                        });
        }
  
    }

//


    

 
}


function pedit(ids)
{
    if($("#p"+ids+" img").attr("src")==tempale+"yes.gif")
    {

        $.ajax({
            type: "POST",
            url: "adminajax.php?act=pedit",
            data: "&id="+ids+"&"+$("#p"+ids+" input").serialize(),
            success: function(msg){
                $("#p"+ids+" img").attr("src",tempale+"edit.gif");
                $("input:text", "#p"+ids).each(function(i,n){
                    $("#p"+ids+">span").eq(i).text($(n).val());
                });
                $("#msg").html(ids+msg);
            }
        });

      
    }
    else
    {
        $("#p"+ids +" img").attr("src",tempale+"yes.gif");
        var lenarr = ["85px","50px"];
        var typear = ["text","text"];
        var namear = ["price2_text","price2"];
        $("span", "#p"+ids).each(function(i,n){
            $(n).html("<input name='"+namear[i]+"' style='width:"+lenarr[i]+";' type='"+typear[i]+"' value='"+$(n).text()+"' />");
        });
    }


   

}

function spedit(ids)
{

    if($("#sp"+ids+" img").attr("src")==tempale+"yes.gif")
    {

        $.ajax({
            type: "POST",
            url: "adminajax.php?act=spedit",
            data: "&id="+ids+"&"+$("#sp"+ids+" input").serialize(),
            success: function(msg){
                $("#sp"+ids+" img").attr("src",tempale+"edit.gif");
                $("input:text", "#sp"+ids).each(function(i,n){
                    $("#sp"+ids+">span").eq(i).text($(n).val());
                });
                $("#msg").html(ids+msg);
            }
        });


    }
    else
    {
        $("#sp"+ids +" img").attr("src",tempale+"yes.gif");
        var lenarr = ["85px","50px"];
        var typear = ["text","text"];
        var namear = ["price_text","price"];
        $("span", "#sp"+ids).each(function(i,n){
            $(n).html("<input name='"+namear[i]+"' style='width:"+lenarr[i]+";' type='"+typear[i]+"' value='"+$(n).text()+"' />");
        });
    }

  

}

function admincheck(inp)
{
     num =0;
        $.ajax({
            type:"GET",
            url:"adminajax.php?act=check&tb="+tbname+"&wht="+what+"&n="+Math.random()+'&inpv='+inp.value,
            dataType:"json",
            async:false,
            success:function (json){
                num =json.num
	}});
        if(num>0)
        {
            return false;
        }
        else
        {
            return true ;
        }
}
	


function adminpass(ids,what,tbname)
{	
	
    if($("#"+what+ids+" img").attr("src")==tempale+"yes.gif")
    {
        $("#"+what+ids+" img").attr("src",tempale+"block.gif");
        isok=0;
    }
    else
    {
        $("#"+what+ids +" img").attr("src",tempale+"yes.gif");
        isok=1
    }
    $.ajax({
        beforeSend:function(){
            $("#msg").html("正在发送");
        },
        type: "post",
        url:"adminajax.php?act=pass",
        data:"id="+ids+"&what="+what+"&isok="+isok+"&tbname="+tbname,
        success: function(comm){
            $("#msg").html($("#passname").text()+comm);
        },
        error:function(){
            $("#msg").html("链接出错");
        }
    });
	
}




function catsh(ids,pid)
{
    $("#abc").hide();
}




function moreinfo(dbgo)
{
    if(!$("input[type=checkbox][name='id[]'][checked]").val())
    {
        alert("请选择操作id");
        return
    }
    if(!$("input[type=radio][name='do'][checked]").val())
    {
        alert("请选择操作的动作");
        return
    }
	
    $.ajax({
        beforeSend:function(){
            $("body").append("<div id='myloadinfo'><br><img src='img/loading.gif'/><br>正在载入中...</div>").show("slow");$("#msg").html("正在发送")
        },
        type: "post",
        url:"adminajax.php?act=dbmore&dggo="+dbgo,
        data:$("input").serialize()+"&catname="+$("#menu").val(),
        success: function(comm){
            //alert();
            $("body").load(window.location.href+" table",function(){
                $("#msg").html(comm);
            });
					
        },
        error:function(){
            $("#msg").html("链接出错");
        }
    });
	
}
function selectall()
{
    $("input[type=checkbox]").attr("checked","checked");
}
function unselectall()
{
    $("input[type=checkbox]").attr("checked","");
}

function admindel(ids,what,dbgo)
{
    if(confirm("你确定要删除吗？")){
        $("#tr"+ids).remove();
        $.get("adminajax.php?act=del&do="+what+"&id="+ids);
        $("#msg").html(ids+"删除成功");
    }else{
        return
    }
}

function adminedit(ids,what,dbgo)
{
	
    $("body").append("<div id='myunput'></div>").show("slow");
    $("#myunput").fadeTo("fast", 0.6);
    $("select").hide();
    $("#myunput").width(document.documentElement.offsetWidth-17).height(document.documentElement.clientHeight>window.screen.height?document.body.clientHeight+document.documentElement.scrollTop:window.screen.height);
    $("body").append("<div id='myshopcert'><img src='img/loading.gif'/></div>");
    $("#myshopcert").css({
        left: (window.screen.width-702)/2 ,
        top:(document.documentElement.scrollTop+30)
    });
    $("#myshopcert").focus();
    $("#myshopcert").load("?act="+what+"&id="+ids+"&dbgo="+dbgo,function()
    {
        loadfunction('cat');
    });
	
}
function editclose()
{
    $("select").show();
    $("#myshopcert").remove();
    $("#myunput").remove();
}


function cukusend(dbgo,tbname)
{
    $.ajax({
        beforeSend:function(){
            $("#myshopcert").html("正在发送");
        },
        type: "post",
        url:"adminajax.php?act="+dbgo,
        data:$(".ajax input").serialize()+"&content="+$("#content").val()+"&pcatid="+$("#menu").val()+"&tbname="+tbname,
        success: function(comm){
            $("#myshopcert").html(comm+"正在载入<br /><img src='img/loading.gif'/>");
            $("#catlist").load(window.location.href+" #catlist" ,function(){
                editclose();
            });
				
        },
        error:function(){
            $("#msg").html("链接出错");
        }
    });
	
}
function gopage(gourl)
{
    $("#catlist").append("<div id='myloadinfo'><br><img src='img/loading.gif'/><br>正在载入中...</div>").show("slow");
    if(gourl==null)
    {
        $("#catlist").load("?page="+$("#page").val());
    }
    else
    {
        $("#catlist").load(gourl,function(){
            $("#myloadinfo").hide("slow");
        });
    }
}


function loadfunction(str)
{
    $("#pcat").change(
        function() {
            $("#catid").load("?act=subcat&slt="+str+"&id="+$("#pcat").val(),
                function(){
                    $('#traddcat').hide();
                    catchang();
                    $("#menu").change();
                });
        } );

}

function catchang(str)
{
    $("#menu").change(
        function() {
            if($("#menu").val()=='add')
            {
                $('#traddcat').show();
            }
            else
            {
                $('#traddcat').hide();
                $("#scatid").load("?act=ssubcat&slt="+str+"&id="+$("#menu").val(),function(){
                    sscat();
                });
            }
        });
}

function sscat()
{
	
    $("#smenu").change(
        function() {
            //$("#catid").load("?act=subcat&slt="+str+"&id="+$("#pcat").val());
            if($("#smenu").val()=='add')
            {
                $('#straddcat').show();
            //alert($("#menu").val());
            }
            else
            {
                $('#straddcat').hide();
		
            }
        });
}



$(document).ready(function(){  
//    $(".list tr").mouseover(function(){
//        $(this).addClass("over");
//    }).mouseout(function(){
//        $(this).removeClass("over");
//    })
//    loadfunction();
//    catchang();
//    sscat();
});

